/* Copyright (C) 2016-2017 HangZhou Zenzet Technology Co., Ltd.
 * All right reserved

 * File:lktstruct.h
 * Author:guojianchuan
 * Date:2017-06-09

 */
 
#ifndef LKT_STRUCT_H
#define LKT_STRUCT_H

#ifdef __cplusplus
extern "C" {
#endif
typedef struct tagColumn
{
    char columnName[COLUMN_NAME_MAX_LEN];
    int  charType; 
    int  typeLen;
}COLUMN_S;

typedef struct tagTable
{
    char tableName[TABLE_NAME_MAX_LEN];
    int columnNum;
    COLUMN_S columnList[COLUMN_MAX_NUM];
}TABLE_S;

typedef struct tagDatabase
{
    char dbName[DATABASE_NAME_MAX_LEN];

    int tableNum;

    TABLE_S tableList[TABLE_MAX_NUM];
}DATABASE_S;

typedef struct tagInstance
{
    int dbNum;
    DATABASE_S dbList[DB_MAX_NUM];
}DATABASE_INSTANCE_S;

typedef struct tagAppDataKey
{
    char key[KEY_MAX_LEN];
    char iv[IV_MAX_LEN];
}APP_DATAKEY_S;

typedef struct tagCompanyKey
{
    char masterKey[COMPANY_MASTER_KEY_LEN];
    char pv[COMPANY_PV_LEN];
}COMPANY_KEY_S;

typedef struct tagCipher
{
    int id;
    char algo[ALGO_NAME_LEN];
    char mode[MODE_NAME];
    char padding[PADDING_NAME];
    int keyLen;
    int ivLen;
}CIPHER_S;

typedef struct tagDataKey
{
    char key[KEY_MAX_LEN];
    char iv[IV_MAX_LEN];
    int mappingid;
    int enableEncrypt;
}DATA_KEY_S;

typedef struct tagColumnStrategy
{
    int used;
    int strategyID;
    char columnName[COLUMN_NAME_MAX_LEN];
    char type[COLUMN_TYPE_NAME_LEN];
    int  searchable;  /* 0:不用于搜索 1:用于搜索 */ 
    char charset[CHARSET_NAME_LEN];    
    int  state;
    DATA_KEY_S dataKey;
    CIPHER_S cipher;
    int  dbIdx;
    int  tblIdx;
}COLUMN_STRATEGY_S;

typedef struct tagTableStrategy
{
    int used;
    char tableName[TABLE_NAME_MAX_LEN];
}TABLE_STRATEGY_S;

typedef struct tagDatabaseStrategy
{
    int used;
    char dbName[DATABASE_NAME_MAX_LEN];
}DB_STRATEGY_S;

typedef struct tagAppInfo
{
    char appAccessSecret[ACCESSKEY_SECRET_MAX_LEN];
           
    APP_DATAKEY_S appDataKey;
    
    COMPANY_KEY_S companyKey;
    
    int dbNum;
    DB_STRATEGY_S dbStrategyList[DB_STRATEGY_MAX_NUM];

    int tableNum;
    TABLE_STRATEGY_S tblStrategyList[TBL_STRATEGY_MAX_NUM];

    int columnNum;
    COLUMN_STRATEGY_S columnStrategyList[COLUMN_STRATEGY_MAX_NUM];
}APP_INFO_S;


typedef struct tagDBSDataSync
{
    pthread_rwlock_t rwLock;
    long long lastSyncTime;
    DATABASE_INSTANCE_S dbInstance;
    APP_INFO_S appInfo;
}DATA_SHM_S;


#ifdef __cplusplus
}
#endif

#endif

